/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.gui.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.toedo.gui.translations.Messages;

public class InsertLinkDialog extends Dialog {

	private Text mTitleText;
	private Text mUrlText;
	
	private String mTitle = null;
	private String mUrl = null;
	
	public InsertLinkDialog(Shell parentShell) {
		super(parentShell);
	}
	
	protected Control createContents(Composite parent) {
		Control contents = super.createContents(parent);
		
		return contents;
	}
	
	protected Control createDialogArea(Composite parent) {
				
		Composite mainPanel = (Composite) super.createDialogArea(parent);
		mainPanel.setLayout(new GridLayout(1, false));
		GridData mainGD = new GridData(SWT.FILL, SWT.FILL, true, true);
		mainGD.widthHint = 350;
		mainPanel.setLayoutData(mainGD);
		
		Composite composite = new Composite(mainPanel, SWT.NONE);		
		composite.setLayout(new GridLayout(2, false));
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		
		Label linkTitleLabel = new Label(composite, SWT.NONE);
		linkTitleLabel.setText(Messages.InsertLinkDialog_LinkTitle);
		
		mTitleText = new Text(composite, SWT.BORDER);
		mTitleText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
		
		Label linkUrlLabel = new Label(composite, SWT.NONE);
		linkUrlLabel.setText(Messages.InsertLinkDialog_LinkUrl);
		
		mUrlText = new Text(composite, SWT.BORDER);
		mUrlText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
		
		return parent;
	}
	
	protected void createButtonsForButtonBar(Composite parent) {
		Button okBtn = createButton(parent, -1, IDialogConstants.OK_LABEL, true);
		Button closeBtn = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
		
		okBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {								 
				mTitle = mTitleText.getText();
				mUrl = mUrlText.getText();
				close();
			}
		});
		
		closeBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {				
				close();				
			}
		});
	}
	
	public String getTitle() {
		return mTitle; 
	}
	
	public String getUrl() {
		return mUrl; 
	}

}
